// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  const _ = db.command;
  console.log(event.search||'')
  let where = {};
  if(event.longitude){
    where.point = _.geoNear({
      geometry: db.Geo.Point(event.longitude, event.latitude),
      minDistance: 0,
      maxDistance: 25000,
    });
  }
  if(event.search+''){
    where.title = db.RegExp({
      regexp: event.search+''||"",
      options:"i"     //忽略大小写
    })
  }
  

    return await db.collection('job').where(where)
    .get()
  
  
}